
package stratego.java.ssm.gui;

import java.util.EventObject;

import stratego.java.ssm.Board;
import stratego.java.ssm.piece.Piece;

/**
 * <code>public final class BoardEvent extends EventObject</code>
 * <p>
 * This object represents some event that occurs on the board, the GameCanvas object. Currently,
 * only clicks are supported (and that may be all).
 * </p>
 * 
 * @author Mark Aligbe
 * 
 */
public final class BoardEvent extends EventObject
{
	private static final long	serialVersionUID	= 3003228434190366805L;
	/** The Board which was being used by the GameCanvas object. */
	private final Board	      board;
	// The x and y grid square coordinates of where the mouse clicked, and the button that clicked
	private final int	      x, y, button;
	/** The Piece that was at the clicked location */
	private final Piece	      piece;
	
	/**
	 * <code>public BoardEvent(GameCanvas source, Board board, int x, int y, int button, Piece piece)</code>
	 * <p>
	 * Constructs an immutable BoardEvent object based on the location of the click fired from
	 * GameCanvas.
	 * </p>
	 * 
	 * @param source
	 *            - The GameCanvas that created this event.
	 * @param board
	 *            - The Board being represented by the GameCanvas.
	 * @param x
	 *            - The grid square - x coordinate of the click.
	 * @param y
	 *            - The grid square - y coordinate of the click.
	 * @param button
	 *            - The button used to click on the board.
	 * @param piece
	 *            - The Piece at the location of the click.
	 */
	public BoardEvent(GameCanvas source, Board board, int x, int y, int button, Piece piece)
	{
		super(source);
		this.board = board;
		this.x = x;
		this.y = y;
		this.button = button;
		this.piece = piece;
	}
	
	/**
	 * <code>public Board getBoard()</code>
	 * <p>
	 * Gets the Board that this BoardEvent was triggered from.
	 * </p>
	 * 
	 * @return The Board that contains the same Piece as this BoardEvent.
	 */
	public Board getBoard()
	{
		return board;
	}
	
	/**
	 * <code>public int getX()</code>
	 * <p>
	 * Returns the grid-square x coordinate of the click.
	 * </p>
	 * 
	 * @return An int between 0 and getBoard().getBoard().length-1.
	 */
	public int getX()
	{
		return x;
	}
	
	/**
	 * <code>public int getY()</code>
	 * <p>
	 * Returns the grid-square y coordinate of the click.
	 * </p>
	 * 
	 * @return An int between 0 and getBoard().getBoard().length-1.
	 */
	public int getY()
	{
		return y;
	}
	
	/**
	 * <code>public int getButton()</code>
	 * <p>
	 * Returns the button used to click on GameCanvas.
	 * </p>
	 * 
	 * @return An int from 1 to MouseInfo.getNumberOfButtons().
	 */
	public int getButton()
	{
		return button;
	}
	
	/**
	 * <code>public Piece getPiece()</code>
	 * <p>
	 * Returns the piece that was at the location of the mouse click.
	 * </p>
	 * 
	 * @return The piece at getBoard().getBoard()[getX()][getY()], without having to resolve that
	 *         chain
	 */
	public Piece getPiece()
	{
		return piece;
	}
	
	@Override
	/**Returns pertinent information about this BoardEvent*/
	public String toString()
	{
		return "Grid square: (" + x + "," + y + "). Piece: " + piece.toString() + ". Button: "
		        + button;
	}
}
